<html>
<head><meta charset="utf-8"><title>Type inference failing on BoxFutures? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html">Type inference failing on BoxFutures?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231154170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231154170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231154170">(Mar 20 2021 at 15:54)</a>:</h4>
<p>Hello- I'm working with complex futures and have been seeing a lot of inference issues around futures; BoxFuture usage is hit pretty hard by it, so anything using async functions on traits is pretty much "just annotate everything" if you want to see any useful types at all.</p>
<p>What I'm seeing is that BoxFuture and similar are typed successfully, but once you <code>await</code> them, the type inference fails to deduce the inner type anymore, and shows <code>&lt;&lt;{unknown} as Deref&gt;::Target as Future&gt;::Output</code> or similar depending on the affected types.</p>
<p>I've made a repro at <a href="https://gist.github.com/Dessix/2d06becd23ff9291d8fab4015d17975b">https://gist.github.com/Dessix/2d06becd23ff9291d8fab4015d17975b</a> with several scenarios, showing what infers and what doesn't.</p>
<p>Also, I've seen this occur on <code>Instrument</code> streams and futures from the tokio <code>tracing</code> library; Instrumenting a future makes it go from resolving the type to producing <code>{unknown}</code> in a nested set of typecasts and associated types.</p>
<p>Additionally, while troubleshooting I've determined that this seems to occur independently of the Chalk environment variables for maximum iterations and tree depth (I set them 10x their defaults and saw no change in the inference result). I haven't been able to find a GitHub issue that fits this scenario.</p>



<a name="231158656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231158656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231158656">(Mar 20 2021 at 17:17)</a>:</h4>
<p>hmm, it seems to work fine if the <code>.await</code> is removed, odd</p>



<a name="231159209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231159209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231159209">(Mar 20 2021 at 17:27)</a>:</h4>
<p>Yeah, I noted that in my repro on <a href="https://gist.github.com/Dessix/2d06becd23ff9291d8fab4015d17975b#file-lib-rs-L44">line 44</a>, where it infers correctly until the <code>.await</code>. Not sure why.</p>



<a name="231159689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231159689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231159689">(Mar 20 2021 at 17:35)</a>:</h4>
<p>can you file a bug for this?</p>



<a name="231159708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231159708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231159708">(Mar 20 2021 at 17:35)</a>:</h4>
<p>Working on it right now- any additional info you'd like beyond a copy-paste of my opening post to this thread?</p>



<a name="231159751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231159751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231159751">(Mar 20 2021 at 17:36)</a>:</h4>
<p>that's already plenty :)</p>



<a name="231159780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231159780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231159780">(Mar 20 2021 at 17:36)</a>:</h4>
<p>Cool- I also went through the entire issue backlog for anything involving <code>infer</code>, <code>inference</code>, <code>associated type</code>, and <code>chalk</code>; nothing seemed to fit, as noted above, so here's hoping it's not just a duplicate ^^</p>



<a name="231160036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231160036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231160036">(Mar 20 2021 at 17:41)</a>:</h4>
<p>See also <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5886">https://github.com/rust-analyzer/rust-analyzer/issues/5886</a></p>



<a name="231160104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231160104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231160104">(Mar 20 2021 at 17:42)</a>:</h4>
<p>hm that does seem to be the same issue</p>



<a name="231160659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231160659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231160659">(Mar 20 2021 at 17:51)</a>:</h4>
<p>Yup</p>



<a name="231160947"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231160947" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231160947">(Mar 20 2021 at 17:56)</a>:</h4>
<p>Interesting- the difference I see is that Output is String in that one, where in mine it was <code>{unknown}</code>. Are you sure this is the same? Later comments show similar, but... under impl? If they're the same I'll avoid posting a dupe.</p>



<a name="231161052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231161052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231161052">(Mar 20 2021 at 17:58)</a>:</h4>
<p>I think the screenshots in the last message show the same thing as yours</p>



<a name="231161199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231161199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231161199">(Mar 20 2021 at 18:00)</a>:</h4>
<p>I'll post my repros there and note that it also occurs for BoxStream and <a href="https://docs.rs/tracing/0.1.25/tracing/instrument/struct.Instrumented.html">tracing::Instrumented</a></p>
<p>Edit: Added <a href="https://github.com/rust-analyzer/rust-analyzer/issues/5886#issuecomment-803435748">a comment</a> on the issue with my repros posted.</p>



<a name="231164282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231164282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231164282">(Mar 20 2021 at 18:52)</a>:</h4>
<p><del>Interesting note to add- it appears that <code>futures::executor::block_on</code> also has this issue, based on the screenshots provided in the comment by user woody77.</del><br>
Scratch that part- it's just extrapolating the type from the <code>async</code> block above it.</p>
<p>I'm also not clear on what's actually going on here, but Florian marked it as actionable, so I presume there's some context I'm missing?</p>



<a name="231165067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/231165067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#231165067">(Mar 20 2021 at 19:05)</a>:</h4>
<p>the actionable part is debugging it and finding out what's going on</p>



<a name="232554984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/232554984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoey <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#232554984">(Mar 31 2021 at 08:41)</a>:</h4>
<p>Looks like someone figured it out and made a patch: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8266">https://github.com/rust-analyzer/rust-analyzer/pull/8266</a><br>
Just waiting for code review and merge now :)</p>



<a name="232570369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Type%20inference%20failing%20on%20BoxFutures%3F/near/232570369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Type.20inference.20failing.20on.20BoxFutures.3F.html#232570369">(Mar 31 2021 at 10:55)</a>:</h4>
<p>Only thanks to what Jonas figured out though, from there on finding a minimal repro wasn't that much work anymore</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>